package com.anguin.mylibrary.service.impl;

import com.anguin.mylibrary.entity.BookEntity;
import com.anguin.mylibrary.mapper.BookMapper;
import com.anguin.mylibrary.service.BookService;
import com.anguin.mylibrary.service.ex.GetDataException;
import com.anguin.mylibrary.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService
{
    @Autowired
    BookMapper bookMapper;

    @Override
    public List<BookEntity> getAllBookList()
    {
        List<BookEntity> list = bookMapper.getAllBookList();
        if (list == null)
        {
            throw new GetDataException("获取数据失败，未知错误");
        }
        return list;
    }

    @Override
    public BookEntity getBookByName(String query)
    {
        BookEntity book = bookMapper.getBookByName(query);

        if (book == null)
        {
            throw new GetDataException("当前图书不存在");
        }
        return book;
    }
}
